项目三-指定区间[A,B]之间的素数和.c 299 B

123456789101112131415161718192021
  1. #include <stdio.h>
  2. int main() {
  3. int a, b, sum = 0;
  4. scanf("%d %d",&a,&b);
  5. int c;
  6. for(c = a; c <= b; c++) {
  7. int i, is = 1;
  8. for(i = 2; i < c; i++) {
  9. if(c % i == 0) {
  10. is = 0;
  11. break;
  12. }
  13. }
  14. if(is == 1) sum += c;
  15. }
  16. printf("%d-%d之间的素数和为%d",a,b,sum);
  17. return 0;
  18. }